/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view.panels;

import control.OrderController;
import java.awt.Graphics;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import model.Produkt;
import model.Sandwich;
import utility.ImageToolbox;
import utility.NotLoggedInException;

/**
 *
 * @author Jeppe
 */
public class ProduktListePanel extends javax.swing.JPanel {
    private MenuPanel menuPanel;
    private Produkt etProdukt;
    /**
     * Creates new form ProduktPanel
     */
    public ProduktListePanel(MenuPanel menuPanel, Produkt produkt) {
        initComponents();
        this.menuPanel = menuPanel;
        this.etProdukt = produkt;
        titelLabel.setText(produkt.getTitel());
        beskrivelseLabel.setText(produkt.getBeskrivelse());
        ratingLabel.setText(produkt.getRating()+"");
        prisLabel.setText(produkt.getPris()+",-");
        if (produkt instanceof Sandwich) {
            Sandwich sandwich = (Sandwich) produkt;
            thumbnailLabel.setIcon(sandwich.getImgIcon());
        }
        thumbnailLabel.repaint();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        thumbnailLabel = new javax.swing.JLabel(){
            public void paint(Graphics g){
                ImageToolbox.drawImage(g, (ImageIcon) thumbnailLabel.getIcon(), 0, 0, thumbnailLabel.getWidth(), thumbnailLabel.getHeight());
            }
        };
        titelLabel = new javax.swing.JLabel();
        ratingPanel = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        ratingLabel = new javax.swing.JLabel();
        beskrivelseLabel = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        prisLabel = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setBackground(new java.awt.Color(255, 255, 255));
        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        titelLabel.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        titelLabel.setText("Titel");

        ratingPanel.setOpaque(false);
        ratingPanel.setLayout(null);

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel3.setText("Rating:");
        jLabel3.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        ratingPanel.add(jLabel3);
        jLabel3.setBounds(10, 10, 40, 15);

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel4.setText("/10");
        ratingPanel.add(jLabel4);
        jLabel4.setBounds(80, 10, 20, 14);

        ratingLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        ratingLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        ratingLabel.setText("10");
        ratingPanel.add(ratingLabel);
        ratingLabel.setBounds(59, 10, 20, 14);

        beskrivelseLabel.setText("Beskrivelse");

        jLabel1.setText("Pris:");

        jButton1.setText("Læg i kurv");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(1, 1, 1)
                .addComponent(thumbnailLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(titelLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(beskrivelseLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(10, 10, 10))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(prisLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(ratingPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(12, 12, 12))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(9, 9, 9)
                .addComponent(titelLabel)
                .addGap(5, 5, 5)
                .addComponent(beskrivelseLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(prisLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(thumbnailLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(jButton1)
                        .addGap(18, 18, 18)
                        .addComponent(ratingPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(0, 1, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            OrderController.getInstance().lægProduktIKurv(menuPanel.getSelectedDate(), etProdukt);
        } catch (NotLoggedInException ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Ikke logget ind", 3);
        }
    }//GEN-LAST:event_jButton1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel beskrivelseLabel;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel prisLabel;
    private javax.swing.JLabel ratingLabel;
    private javax.swing.JPanel ratingPanel;
    private javax.swing.JLabel thumbnailLabel;
    private javax.swing.JLabel titelLabel;
    // End of variables declaration//GEN-END:variables
}
